const path = require('path');

const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack'); // 用于访问内置插件
const VueLoaderPlugin = require('vue-loader/lib/plugin')

const TerserPlugin = require("terser-webpack-plugin");
module.exports = {
    entry: './src/main.js',
    mode: 'none',
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: 'bundle.js',
    },
    devServer: {
        static: {
            directory: path.join(__dirname, 'dist'),
        },
        compress: true,
        port: 9000,
    },
    resolve: {
        extensions: [".js", ".vue", ".json"], 
        alias: {
            'vue$': 'vue/dist/vue.js',
        },
    },
    optimization: {
        minimize: true,
        minimizer: [new TerserPlugin()],
      },
    module: {
        rules: [
            {
                test: /\.(css|less)$/i,
                use: [
                    { loader: 'style-loader' },
                    {
                        loader: 'css-loader', options: {
                            esModule: false
                        }
                    },
                    { loader: 'less-loader' }
                ],
            },
            {
                test: /\.(png|jpg|gif)$/i,
                generator:{ 
                    filename:'img/[name].[hash:8][ext]',
                  },
                type: 'asset/resource',
            },
            {
                test: /\.vue$/,
                use: ["vue-loader"]
            }
        ],
    },
    plugins: [
        new VueLoaderPlugin(),
        new HtmlWebpackPlugin({ template: 'index.html' }),
    ],
};